package com.ruoyi.project.newhope.materialInspection.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.newhope.inspection.domain.NewHopeInspection;
import com.ruoyi.project.newhope.inspection.mapper.NewHopeInspectionMapper;
import com.ruoyi.project.newhope.material.domain.NewHopeMaterial;
import com.ruoyi.project.newhope.material.mapper.NewHopeMaterialMapper;
import com.ruoyi.project.newhope.warning.mapper.NewHopeWarningMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.newhope.materialInspection.mapper.NewHopeMaterialInspectionMapper;
import com.ruoyi.project.newhope.materialInspection.domain.NewHopeMaterialInspection;
import com.ruoyi.project.newhope.materialInspection.service.INewHopeMaterialInspectionService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 物料检测项目设置(中间[物料主数据设置-化验项目设置])Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Service
public class NewHopeMaterialInspectionServiceImpl implements INewHopeMaterialInspectionService 
{
    @Autowired
    private NewHopeMaterialInspectionMapper newHopeMaterialInspectionMapper;
    @Autowired
    private NewHopeWarningMapper newHopeWarningMapper;

    /**
     * 查询物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * 
     * @param id 物料检测项目设置(中间[物料主数据设置-化验项目设置])ID
     * @return 物料检测项目设置(中间[物料主数据设置-化验项目设置])
     */
    @Override
    public NewHopeMaterialInspection selectNewHopeMaterialInspectionById(Long id)
    {
        return newHopeMaterialInspectionMapper.selectNewHopeMaterialInspectionById(id);
    }

    /**
     * 查询物料检测项目设置(中间[物料主数据设置-化验项目设置])列表
     * 
     * @param newHopeMaterialInspection 物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * @return 物料检测项目设置(中间[物料主数据设置-化验项目设置])
     */
    @Override
    public List<NewHopeMaterialInspection> selectNewHopeMaterialInspectionList(NewHopeMaterialInspection newHopeMaterialInspection)
    {
        List<NewHopeMaterialInspection> newHopeMaterialInspections = newHopeMaterialInspectionMapper.selectNewHopeMaterialInspectionList(newHopeMaterialInspection);
        return newHopeMaterialInspections;
    }

    /**
     * 新增物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * 
     * @param newHopeMaterialInspection 物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * @return 结果
     */
    @Override
    public int insertNewHopeMaterialInspection(NewHopeMaterialInspection newHopeMaterialInspection)
    {
        newHopeMaterialInspection.setCreateTime(DateUtils.getNowDate());
        return newHopeMaterialInspectionMapper.insertNewHopeMaterialInspection(newHopeMaterialInspection);
    }

    /**
     * 修改物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * 
     * @param newHopeMaterialInspection 物料检测项目设置(中间[物料主数据设置-化验项目设置])
     * @return 结果
     */
    @Override
    public int updateNewHopeMaterialInspection(NewHopeMaterialInspection newHopeMaterialInspection)
    {
        newHopeMaterialInspection.setUpdateTime(DateUtils.getNowDate());
        int i = newHopeMaterialInspectionMapper.updateNewHopeMaterialInspection(newHopeMaterialInspection);
        if (i == 1) {
            // 清楚报警记录中该类指标的已有报警记录
            newHopeWarningMapper.deleteNewHopeWarning(null, newHopeMaterialInspection.getMaterialId(), newHopeMaterialInspection.getInspectionId());
        }
        return i;
    }

    /**
     * 删除物料检测项目设置(中间[物料主数据设置-化验项目设置])对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteNewHopeMaterialInspectionByIds(String ids)
    {
        return newHopeMaterialInspectionMapper.deleteNewHopeMaterialInspectionByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除物料检测项目设置(中间[物料主数据设置-化验项目设置])信息
     * 
     * @param id 物料检测项目设置(中间[物料主数据设置-化验项目设置])ID
     * @return 结果
     */
    @Override
    public int deleteNewHopeMaterialInspectionById(Long id)
    {
        return newHopeMaterialInspectionMapper.deleteNewHopeMaterialInspectionById(id);
    }

    @Override
    public Integer isExist(NewHopeMaterialInspection newHopeMaterialInspection) {
        return newHopeMaterialInspectionMapper.isExist(newHopeMaterialInspection);
    }
}
